package com.shiro.controller;

import com.shiro.domain.User;
import com.shiro.redis.UserKey;
import com.shiro.result.Result;
import com.shiro.redis.RedisService;
import com.shiro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    RedisService redisService;

    @RequestMapping("/db/get")
    @ResponseBody
    public Result<User> dbGet(){
        User user = userService.getById(1);
        return Result.success(user);
    }

    @RequestMapping("/redis/get")
    @ResponseBody
    public Result<User> redisGet(){
        User user =redisService.get(UserKey.getById,"1",User.class);
        return Result.success(user);
    }

    @RequestMapping("/redis/set")
    @ResponseBody
    public Result<Boolean> redisSet(){
        User user = userService.getById(1);
        boolean v1 =redisService.set(UserKey.getById,"1",user);
        System.out.println(v1);
        String str =redisService.get(UserKey.getById,"1",String.class);
        return Result.success(v1);
    }
}
